/*
 * Created by JFormDesigner on Mon Dec 13 08:29:47 CST 2021
 */

package com.cn.项目.飞机预约管理系统.Logining;

import com.cn.项目.utils.JdbcUtils;
import com.cn.项目.飞机预约管理系统.Maininterface.MenuJframe;
import com.cn.项目.飞机预约管理系统.Maininterface.Success;

import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.*;


public class logining extends JFrame {
    public logining() {
        initComponents();
    }
     // 登录按钮
    private void button1ActionPerformed(ActionEvent e) {
        // TODO add your code here
        Connection conn = null;
        PreparedStatement st = null;
        String id = textField1.getText();
        String password = passwordField1.getText();
        ResultSet rs = null;
        try {
             conn = JdbcUtils.getConnection();
             String sql="select *from manager where id=? and password=?";
             st = conn.prepareStatement(sql);
             st.setString(1, id);
             st.setString(2,password);
             rs = st.executeQuery();
            if (rs.next()){
                //登录成功提示
                new Success();
                //进入主界面
                new MenuJframe();
                this.dispose();
            }
            else {
                new Errorprompt();
            }

        } catch (SQLException e1) {
            e1.printStackTrace();
        }
    }

    //注册按钮
    private void button2ActionPerformed(ActionEvent e) {
        // TODO add your code here
        new Register();
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        label1 = new JLabel();
        label2 = new JLabel();
        textField1 = new JTextField();
        label3 = new JLabel();
        passwordField1 = new JPasswordField();
        button1 = new JButton();
        button2 = new JButton();
        label4 = new JLabel();

        //======== this ========
        setVisible(true);
        setAutoRequestFocus(false);
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- label1 ----
        label1.setText("管理者登录");
        label1.setFont(label1.getFont().deriveFont(label1.getFont().getStyle() & ~Font.ITALIC, label1.getFont().getSize() + 16f));
        label1.setForeground(new Color(0, 204, 0));
        contentPane.add(label1);
        label1.setBounds(120, 15, 170, 35);

        //---- label2 ----
        label2.setText("账号");
        label2.setFont(label2.getFont().deriveFont(label2.getFont().getSize() + 6f));
        contentPane.add(label2);
        label2.setBounds(35, 75, 65, 35);

        //---- textField1 ----
        textField1.setText("请输入你的账号");
        contentPane.add(textField1);
        textField1.setBounds(135, 75, 185, 35);

        //---- label3 ----
        label3.setText("密码：");
        label3.setFont(label3.getFont().deriveFont(label3.getFont().getSize() + 6f));
        contentPane.add(label3);
        label3.setBounds(35, 155, 60, 30);
        contentPane.add(passwordField1);
        passwordField1.setBounds(135, 155, 185, 35);

        //---- button1 ----
        button1.setText("登录");
        button1.setForeground(new Color(0, 255, 51));
        button1.setFont(button1.getFont().deriveFont(button1.getFont().getSize() + 6f));
        button1.addActionListener(e -> button1ActionPerformed(e));
        contentPane.add(button1);
        button1.setBounds(50, 245, 85, 35);

        //---- button2 ----
        button2.setText("注册");
        button2.setForeground(new Color(0, 153, 153));
        button2.setFont(button2.getFont().deriveFont(button2.getFont().getSize() + 6f));
        button2.addActionListener(e -> button2ActionPerformed(e));
        contentPane.add(button2);
        button2.setBounds(235, 245, 85, 35);

        //---- label4 ----
        label4.setText("请注意大小写");
        label4.setForeground(new Color(204, 51, 0));
        contentPane.add(label4);
        label4.setBounds(140, 195, 115, 25);

        contentPane.setPreferredSize(new Dimension(400, 360));
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

        // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
        private JLabel label1;
        private JLabel label2;
        private JTextField textField1;
        private JLabel label3;
        private JPasswordField passwordField1;
        private JButton button1;
        private JButton button2;
        private JLabel label4;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
